﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Pan
{
    public partial class modpwd : System.Web.UI.Page
    {
        protected string uname;

        protected void Page_PreInit(object sender, EventArgs e)
        {
            Master.needLogin = true;
            Master.side = 4;
        }

        protected void Page_Init(object sender, EventArgs e)
        {
            this.uname = Master.uname;
        }

        protected void Submit_Click(object sender, EventArgs e)
        {
            if (Newpass.Text != Confirmpass.Text)
            {
                Master.RespLabel.Text = "<script>layui.use('layer',function(){layui.layer.alert('两次密码输入不一致')})</script>";
                return;
            }
            SqlConnection conn = new SqlConnection();
            conn.ConnectionString = ConfigurationManager.ConnectionStrings["PanConnectionString"].ToString();
            Master.RespLabel.Text = "";
            try
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = conn;
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "ModiPwd";
                cmd.Parameters.Add("@uid", SqlDbType.Int).Value = Master.uid;
                cmd.Parameters.Add("@ori", SqlDbType.VarChar, 255).Value = Oripass.Text.Trim();
                cmd.Parameters.Add("@new", SqlDbType.VarChar, 255).Value = Newpass.Text.Trim();
                if (cmd.ExecuteNonQuery() > 0)
                {
                    Session.Clear();
                    Master.RespLabel.Text = "<script>layui.use('layer',function(){layui.layer.msg('密码修改成功，请重新登录',{time: 2000, shade:0.3},function(){window.location.href='/login.aspx'})})</script>";
                }
                else
                {
                    Master.RespLabel.Text = "<script>layui.use('layer',function(){layui.layer.alert('原密码错误')})</script>";
                }
            }
            catch (Exception err)
            {
                Master.RespLabel.Text = "<script>layui.use('layer',function(){layui.layer.alert('" + err.Message + "')})</script>";
            }
            finally
            {
                conn.Close();
            }
        }
    }
}